const app = getApp()
console.log(app.token);

Page({
  data: {
    dialogVisible: false,
    list: [],
    statusMsg: {
      1: '审核中',
      2: '审核成功',
      3: '审核失败'
    },
    statusType: {
      1: 'info',
      2: 'success',
      3: 'fail'
    }
  },
  onShow() {
    this.getRoomList()
  },
  //获取查询我的房屋列表
  async getRoomList() {
    const res = await wx.http.get('/room')
    this.setData({
      list: res.data
    })
  },
  //侧滑
  swipeClose(ev) {
    const { position, instance } = ev.detail
    const id = ev.mark.id
    this.setData({
      id: id
    })
    if (position === 'right') {
      // 显示 Dialog 对话框
      this.setData({
        dialogVisible: true,
      })
      // swiper-cell 滑块关闭
      instance.close()
    }
  },
  async deleteRoom(id) {
    await wx.http.delete(`/room/${id}`)
  },
  //删除房屋
  async dialogClose(e) {
    //确认按钮
    if (e.detail === 'confirm') {
      await this.deleteRoom(this.data.id)
      wx.utils.toast('删除房屋成功')
      this.getRoomList()
    }
  },
  //跳转房屋详情
  goDetail(e) {
    console.log(e.mark.id)
    wx.navigateTo({
      url: '/house_pkg/pages/detail/index?id=' + e.mark.id,
    })
  },

  addHouse() {
    wx.navigateTo({
      url: '/house_pkg/pages/locate/index',
    })
  },
})
